StatsPortlet = Class.extend({
	init: function()	{
		this.name = "StatsPortlet";
		this.interval = 300000;
	},
	
	onBegin: function()	{
		this.model = {};
	},
	
	run: function()	{
		this.getPortletPlaceholder().drawToCanvas(this.render());
		this.fetch();
		this.startInterval(this.interval, this.fetch);
	},
	
	fetch: function()	{
		var obj = this;
		this.onAjax('ajax', 'count-users', {}, 'GET', {
			'onSuccess': function(ret)	{
				obj.requestForEffectiveResource('UserTotal').html(ret);
			}
		});
		this.onAjax('ajax', 'count-questions', {}, 'GET', {
			'onSuccess': function(ret)	{
				obj.requestForEffectiveResource('QuestionTotal').html(ret);
			}
		});
		this.onAjax('ajax', 'count-answers', {}, 'GET', {
			'onSuccess': function(ret)	{
				obj.requestForEffectiveResource('AnswerTotal').html(ret);
			}
		});
	},
	
	onEnd: function()	{
		this.stopInterval();
	}
}).implement(PortletInterface).implement(AjaxInterface).implement(RenderInterface).implement(IntervalTimerInterface);

HallOfFamePortlet = StatsPortlet.extend({
	init: function()	{
		this._super();
		this.name = "HallOfFamePortlet";
	},
	
	fetch: function()	{
		var obj = this;
		this.onAjax('ajax', 'get-most-voted-user', {}, 'GET', {
			'onSuccess': function(ret)	{
				obj.requestForEffectiveResource('MostVoted').html(obj.renderView('MostVotedTmpl', {user: ret}));
			}
		});
		this.onAjax('ajax', 'get-most-answer-user', {}, 'GET', {
			'onSuccess': function(ret)	{
				obj.requestForEffectiveResource('MostAnswer').html(obj.renderView('MostAnswerTmpl', {user: ret}));
			}
		});
	}
}).implement(PortletInterface).implement(AjaxInterface).implement(RenderInterface).implement(IntervalTimerInterface);

FeedbackListPortlet = StatsPortlet.extend({
	init: function()	{
		this.name = "FeedbackListPortlet";
		this.interval = 600000;
	},
	
	run: function()	{
		this.fetch();
		this.startInterval(this.interval, this.fetch);
	},
	
	fetch: function()	{
		var obj = this;
		obj.getPortletPlaceholder().paintCanvas(obj.render());
		this.onAjax('ajax', 'get-feedback-list', {}, 'GET', {
			'onSuccess': function(ret)	{
				var model = {};
				model.feedbacks = ret;
				obj.requestForEffectiveResource('ContentPlaceholder').html(obj.renderView('Content', model));
			}
		});
	}
}).implement(PortletInterface).implement(AjaxInterface).implement(RenderInterface).implement(IntervalTimerInterface);;